package com.koalac.ironman.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;

public class ResourceUtil {

	/**
	 * 取得dimen资源的像素值
	 * 
	 * @param context
	 * @param dimenId
	 *            资源id
	 * @return
	 */
	public static int getDimension(Context context, int dimenId) {
		Resources resources = context.getResources();
		return resources.getDimensionPixelSize(dimenId);
	}

	/**
	 * 根据资源名取得资源id
	 * 
	 * @param context
	 * @param defType
	 *            如drawable、string、values等
	 * @param resName
	 * @return
	 */
	public static int getResourceId(Context context, String defType,
			String resName) {
		Resources resources = context.getResources();
		return resources.getIdentifier(resName, defType,
				context.getPackageName());
	}

	/**
	 * 根据uri取得图片
	 * 
	 * @param context
	 * @param uri
	 * @return
	 * @throws IOException
	 */
	public static Bitmap getBitmap(Context context, Uri uri) throws IOException {
		ContentResolver resolver = context.getContentResolver();
		InputStream is = resolver.openInputStream(uri);
		Bitmap bitmap = BitmapFactory.decodeStream(is);
		if (is != null) {
			is.close();
		}
		return bitmap;
	}
	
	
}
